package lab02.test23;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int year;
        int systemYear;
        int mounth;
        int systemMounth;
        int day;
        int systemDay;
        int mounthDays;
        int sumDays = 0;


        /*输入生日信息*/
        System.out.println("请输入你的生日信息：\n例如：19000101");
        String birthday = sc.nextLine();

        /*获取年月日*/
        year = Integer.parseInt(birthday.substring(0, 4));
        mounth = Integer.parseInt(birthday.substring(4, 6));
        day = Integer.parseInt(birthday.substring(6, 8));

        /*获取系统时间年月日*/
        Calendar now = Calendar.getInstance();

        systemYear = Integer.parseInt(String.valueOf(now.get(Calendar.YEAR)));
        systemMounth = Integer.parseInt(String.valueOf((now.get(Calendar.MONTH) + 1)));
        systemDay = Integer.parseInt(String.valueOf(now.get(Calendar.DAY_OF_MONTH)));


        //为了方便，需要判断生日月份与系统月份的大小
        int max;
        int min;
        if (mounth > systemMounth) {
            max = mounth;
            min = systemMounth;

        } else if (mounth < systemMounth) {
            max = systemMounth;
            min = mounth;
        } else {
            max = 0;
            min = 0;
        }

        //计算两月份之间的天数
        for (int i = min; i < max; i++) {
            switch (i) {
                case 12: {
                    sumDays += 31;
                    break;
                }
                case 11: {
                    sumDays += 30;
                    break;
                }
                case 10: {
                    sumDays += 31;
                    break;
                }
                case 9: {
                    sumDays += 30;
                    break;
                }
                case 8: {
                    sumDays += 31;
                    break;
                }
                case 7: {
                    sumDays += 31;
                    break;
                }
                case 6: {
                    sumDays += 30;
                    break;
                }
                case 5: {
                    sumDays += 31;
                    break;
                }
                case 4: {
                    sumDays += 30;
                    break;
                }
                case 3: {
                    sumDays += 31;
                    break;
                }
                case 2: {
                    /*判断当前年份是否为闰年*/
                    if ((systemYear % 4 == 0 && systemYear % 100 != 0) || systemYear % 400 == 0) {
                        sumDays += 29;
                        break;
                    } else {
                        sumDays += 28;
                        break;
                    }

                }
                case 1: {
                    sumDays += 31;
                    break;
                }
                case 0: {
                    sumDays += 0;
                    break;
                }
                default: {
                    System.out.println("月份错误！！");
                }

            }

        }

        if (mounth > systemMounth) {
            sumDays += day - systemDay;
            System.out.println("距离生日还有" + sumDays + "天！");

        } else if (systemMounth > mounth) {
            sumDays += systemDay - day;
            System.out.println("生日已过：" + sumDays + "天！");
        } else {

            if (day == systemDay) {
                System.out.println("祝你生日快乐！！");
            } else if (day < systemDay) {
                sumDays += systemDay - day;
                System.out.println("生日已过：" + sumDays + "天！");
            } else {
                sumDays += day - systemDay;
                System.out.println("距离生日还有" + sumDays + "天！");
            }
        }

        //判断生日是星期几
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = new GregorianCalendar();
        cal.set(year, mounth, day);

        switch (cal.get(Calendar.DAY_OF_WEEK) + 1) {
            case 1: {
                System.out.println("你的生日是星期一！");
                break;
            }
            case 2: {
                System.out.println("你的生日是星期二！");
                break;
            }
            case 3: {
                System.out.println("你的生日是星期三！");
                break;
            }
            case 4: {
                System.out.println("你的生日是星期四！");
                break;
            }
            case 5: {
                System.out.println("你的生日是星期五！");
                break;
            }
            case 6: {
                System.out.println("你的生日是星期六！");
                break;
            }
            case 7: {
                System.out.println("你的生日是星期天！");
                break;
            }
            default: {
                System.out.println("获取星期错误！");
            }
        }

    }
}
